/*
 * @Description: 
 * @Author: 赵大壮
 * @Date: 2024-07-21 17:04:05
 * @LastEditTime: 2024-07-23 13:30:39
 * @LastEditors: 赵大壮
 */
/*
 * @Description: 
 * @Author: 赵大壮
 * @Date: 2021-12-06 17:18:37
 * @LastEditTime: 2021-12-06 17:36:29
 * @LastEditors: 赵大壮
 */
import { Component, Vue, Inject } from "vue-property-decorator";
import DZServiceArticle from "../../service/DZServiceArticle";
import UITinymceEditor from "@/components/ui-editor/UITinymceEditor.vue"
import UIEditor from "@/components/ui-editor/UIEditor.vue"
import UiDialogAddWorks from "@/components/ui-dialog/UiDialogAddWorks.vue"
import DZModelWorks from "../../model/DZModelWorks";
import dzMsgBox from "@/utils/DZMessageBox";

@Component({
    components: { UITinymceEditor, UIEditor, UiDialogAddWorks }
})
export default class Index extends Vue {

    s_article = new DZServiceArticle();

    dialog_add_works = false;

    created() { }

    mounted() {
        this.s_article.m_article.id = (this.$route.query.articleId as string);
        this.s_article.net_list_type_dic();
        if (this.s_article.m_article.id && this.s_article.m_article.id != '') {
            this.s_article.net_details_article();
        }
    }

    beforeDestroy() {

    }

    action_select_list_cover(file) {
        if (file.status == "ready") {
            this.s_article.m_article.listCoverUrl = URL.createObjectURL(file.raw);
            this.s_article.net_upload_image(file.raw, data => {
                this.s_article.m_article.listCover = data;
            }, () => {
                this.s_article.m_article.listCoverUrl = "";
            });
        }
    }

    action_select_banner_cover(file) {
        if (file.status == "ready") {
            this.s_article.m_article.bannerCoverUrl = URL.createObjectURL(file.raw);
            this.s_article.net_upload_image(file.raw, data => {
                this.s_article.m_article.bannerCover = data;
            }, () => {
                this.s_article.m_article.bannerCoverUrl = "";
            });
        }
    }

    action_editor_change(text) {
        this.s_article.m_article.content = text;
    }

    action_add_works(item: DZModelWorks) {
        if (this.s_article.m_article.id && this.s_article.m_article.id != '') {
            this.s_article.m_works = JSON.parse(JSON.stringify(item));
            this.s_article.net_add_works(() => {
                this.s_article.net_details_article();
            })
        } else {
            this.s_article.list_works.push(item);
        }
    }

    action_del_works(index) {
        if (this.s_article.m_article.id && this.s_article.m_article.id != '') {
            this.s_article.m_works.iId = this.s_article.list_works[index].iId;
            dzMsgBox.del("是否删除该视频号？", () => {
                this.s_article.net_del_works(() => {
                    this.s_article.net_details_article();
                })
            })
        } else {
            this.s_article.list_works.splice(index, 1);
        }
    }

    action_add_article() {
        if (this.s_article.m_article.id && this.s_article.m_article.id != '') {
            this.s_article.net_edit_article(() => {
                this.$router.back();
            });
        } else {
            this.s_article.net_add_article(() => {
                this.$router.back();
            });
        }
    }

}